package icedot.library.common.map;

import icedot.library.common.base.Logger;
import icedot.library.common.utils.CommonFun;
import icedot.library.common.utils.StringUtils;

import org.json.JSONObject;

public abstract class LocationInfo 
{	
	protected int 				_locationType;  //地图类型
	public double 				_latitude;		//纬度
	public double 				_longitude;		//经度
	public int 					_satelliteNumber; //卫星个数
	public int 					_id;			//编号
	public float				_radis;			//精度
	public long					_time;			//生成的时间
	public String 				_addr;          //地址
	public String 				_mark;			//备注
	public float 				_speed;			//速度
	
	public Object 				_object;		
	
	public LocationInfo() 
	{
		clear();
	}
	
	public void clear()
	{
		_locationType = 0;
		_latitude = 0;
		_longitude = 0;
		_id = 0;
		_radis = 0;
		_addr = "";
		_time = 0;
		_satelliteNumber = 0;
		_mark = "";
		_object = null;
	}
	
	public abstract boolean updateLocationInfo(Object object);
	public abstract double getDistance(double lat2,double lon2);
	public abstract String getCity();   //返回定位信息中所属城市名称，如“北京市”
	public abstract String getCityCode(); //返回定位信息中的城市编码，如北京市为“010”
	public abstract String getStreet(); //返回街道和门牌号
	public abstract String getDistrict(); //返回定位信息中所属区（县）名称，如“朝阳区”
	public abstract String getProvince(); //返回定位信息中所属省名称，如“河北省”
	
	public String getAddress()
	{
		return _addr;
	}
	
	public double getLatitude()
	{
		return _latitude;
	}
	
	public double getLongitude()
	{
		return _longitude;
	}
	
	public float getRadius()
	{
		return _radis;
	}
	
	public int getSatelliteNumber() 
	{
		return _satelliteNumber;
	}
	
	public long getTime()
	{
		return _time;
	}
	
	public void setTime(long tm)
	{
		_time = tm;
	}
	
	public int getMapTyppe()
	{
		return _locationType;
	}
	
	public void clone(LocationInfo info)
	{
		if(info._locationType == IMapMgr.s_gaode)
		{
			updateLocationInfo(info._object);
		}
		else if(info._locationType == IMapMgr.s_baidu)
		{
			updateLocationInfo(info._object);
		}
	}
	
	@Override
	public String toString()
	{
		try
		{
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("Id", _id);
			jsonObj.put("Lat", _latitude);
			jsonObj.put("Lon", _longitude);
			jsonObj.put("Radis", _radis);
			jsonObj.put("Time", StringUtils.getDateTimeToString(_time, "yyyy-MM-dd HH:mm:ss"));
			jsonObj.put("Addr", _addr);
			jsonObj.put("Mark",_mark);
			jsonObj.put("MapType", _locationType);
			jsonObj.put("Speed", _speed);
			jsonObj.put("SatelliteNumber", _satelliteNumber);
			return jsonObj.toString();
		} catch (Exception e)
		{
			return "";
		}
	}
	
	public void jsonToObj(String str)
	{
		try
		{
			JSONObject jsonObj = new JSONObject(str);
			_id = CommonFun.getInt(jsonObj, "Id");
			_longitude = CommonFun.getDouble(jsonObj, "Lon");
			_latitude = CommonFun.getDouble(jsonObj, "Lat");
			_radis = (float)CommonFun.getDouble(jsonObj, "Radis");
			_addr = CommonFun.getString(jsonObj, "Addr");
			String time = CommonFun.getString(jsonObj, "Time");
			_time = StringUtils.getDateTimeToLong(time, "yyyy-MM-dd HH:mm:ss");
			_mark = CommonFun.getString(jsonObj, "Mark");
			_locationType = CommonFun.getInt(jsonObj, "MapType");
			_speed = (float)CommonFun.getDouble(jsonObj, "Speed");
			_satelliteNumber = CommonFun.getInt(jsonObj, "SatelliteNumber");
		} catch (Exception e)
		{
			Logger.showDebugMsg(Logger.s_error,"Exception", e.getMessage());
		}
	}
}
